import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface IAccess extends mongoose.Document {
	userId: string;
	userType: string;
	path: string;
	method: string;
	ip: string;
	createdAt?: string;
	updatedAt?: string;
}

// 访问记录
const AccessRecordionSchema = new mongoose.Schema<IAccess>(
	{
		userId: {
			type: String,
		},
		userType: {
			type: String,
			enum: ['admin_user', 'client_user', 'visitor_user'],
		},
		path: {
			type: String,
			required: true,
		},
		method: {
			type: String,
			required: true,
		},
		ip: {
			type: String,
			required: true,
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'access_records',
	}
);

export const AccessRecordionModel = mongoose.model('AccessRecordion', AccessRecordionSchema);
